package xyz.archknight.app.loginput.dictionary.gen.ui.component

import xyz.archknight.app.loginput.dictionary.gen.ui.model.WordTableModel
import java.awt.Color
import javax.swing.JTable
import javax.swing.table.DefaultTableCellRenderer
import javax.swing.table.TableCellRenderer

/**
 * 通用词汇表组件
 *
 * @author midnite
 * create at 2020-06-22 11:48 上午
 */
class WordTable(model: WordTableModel) : JTable(model) {
    private val defaultCellRenderer = DefaultTableCellRenderer()
    private val newCellRenderer = DefaultTableCellRenderer()
    private val dirtyCellRenderer = DefaultTableCellRenderer()
    private val removeCellRender = DefaultTableCellRenderer()

    init {
        newCellRenderer.foreground = Color.GREEN
        dirtyCellRenderer.foreground = Color.ORANGE
        removeCellRender.foreground = Color.RED
    }

    override fun getCellRenderer(row: Int, column: Int): TableCellRenderer {
        val wordModel = model as WordTableModel
        if (wordModel[row].new) {
            return newCellRenderer
        }
        if (wordModel[row].dirty) {
            return dirtyCellRenderer
        }
        if (wordModel[row].removed) {
            return removeCellRender
        }
        return defaultCellRenderer
    }
}